package com.atguigu.lease.web.admin.service.impl;

import com.atguigu.lease.model.entity.*;
import com.atguigu.lease.web.admin.mapper.ApartmentInfoMapper;
import com.atguigu.lease.web.admin.service.*;
import com.atguigu.lease.web.admin.vo.agreement.AgreementQueryVo;
import com.atguigu.lease.web.admin.vo.agreement.AgreementVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atguigu.lease.web.admin.mapper.LeaseAgreementMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author asus
* @description 针对表【lease_agreement(租约信息表)】的数据库操作Service实现
* @createDate 2024-08-16 15:37:00
*/
@Service
public class LeaseAgreementServiceImpl extends ServiceImpl<LeaseAgreementMapper, LeaseAgreement>
    implements LeaseAgreementService{
    @Autowired
    LeaseAgreementMapper leaseAgreementMapper;
    @Autowired
    ApartmentInfoService apartmentInfoService;
    @Autowired
    RoomInfoService roomInfoService;
    @Autowired
    PaymentTypeService paymentTypeService;
    @Autowired
    LeaseTermService leaseTermService;
    
    @Override
    public IPage<AgreementVo> pageAgreementByQuery(IPage<AgreementVo> page, AgreementQueryVo queryVo) {
        return leaseAgreementMapper.pageAgreementByQuery(page,queryVo);


    }

    @Override
    public AgreementVo getInfoById(Long id) {
        LeaseAgreement leaseA = this.getById(id);
        ApartmentInfo apartmentInfo = apartmentInfoService.getById(leaseA.getApartmentId());
        RoomInfo roomInfo = roomInfoService.getById(leaseA.getRoomId());
        PaymentType paymentType = paymentTypeService.getById(leaseA.getPaymentTypeId());
        LeaseTerm leaseTerm = leaseTermService.getById(leaseA.getLeaseTermId());
        AgreementVo agreementVo = new AgreementVo();

        BeanUtils.copyProperties(leaseA,agreementVo);
        agreementVo.setApartmentInfo(apartmentInfo);
        agreementVo.setRoomInfo(roomInfo);
        agreementVo.setPaymentType(paymentType);
        agreementVo.setLeaseTerm(leaseTerm);
        return agreementVo;

    }
}




